package deltax.common
{
    import flash.utils.*;

    final public class Util extends Object
    {

        public function Util()
        {
            return;
        }// end function

        public static function makeDWORD(param1:uint = 0, param2:uint = 0, param3:uint = 0, param4:uint = 0) : uint
        {
            return param1 | param2 << 8 | param3 << 16 | param4 << 24;
        }// end function

        public static function makeDwordFromString(param1:String = "", param2:String = "", param3:String = "", param4:String = "") : uint
        {
            return param1.charCodeAt() | param2.charCodeAt() << 8 | param3.charCodeAt() << 16 | param4.charCodeAt() << 24;
        }// end function

        public static function readUcs2String(param1:ByteArray, param2:uint, param3:Boolean = false, param4:Boolean = false) : String
        {
            var _loc_8:uint = 0;
            var _loc_5:* = new String();
            var _loc_6:Boolean = false;
            var _loc_7:uint = 0;
            while (_loc_7 < param2)
            {
                
                if (!param3)
                {
                    _loc_8 = param1.readUnsignedShort();
                }
                else
                {
                    _loc_8 = param1.readUnsignedByte();
                }
                if (!_loc_8)
                {
                    _loc_6 = true;
                }
                else if (!_loc_6)
                {
                    _loc_5 = _loc_5.concat(String.fromCharCode(_loc_8));
                }
                _loc_7 = _loc_7 + 1;
            }
            return _loc_5;
        }// end function

        public static function readUcs2StringWithCount(param1:ByteArray, param2:Boolean = false) : String
        {
            var _loc_3:* = param1.readUnsignedInt();
            return readUcs2String(param1, _loc_3, param2);
        }// end function

        public static function intToFloatInRawBytes(param1:int) : Number
        {
            var _loc_2:* = new ByteArray();
            _loc_2.endian = Endian.LITTLE_ENDIAN;
            _loc_2.writeInt(param1);
            _loc_2.position = 0;
            return _loc_2.readFloat();
        }// end function

        public static function makeGammaString(param1:String) : String
        {
            var _loc_2:* = param1.toLowerCase();
            _loc_2 = _loc_2.replace(/\\/g, "/");
            return _loc_2;
        }// end function

        public static function hasFlag(param1:uint, param2:uint) : Boolean
        {
            return (param1 & param2) != 0;
        }// end function

        public static function setFlag(param1:uint, param2:uint, param3:Boolean) : uint
        {
            if (param3)
            {
                return param1 | param2;
            }
            return param1 & ~param2;
        }// end function

        public static function convertOldTextureFileName(param1:String, param2:Boolean = true) : String
        {
            param1 = param1.replace(".tex", ".ajpg");
            param1 = param1.replace(".tga", ".ajpg");
            param1 = param1.replace(".bmp", ".ajpg");
            if (param2)
            {
                param1 = param1.replace(".png", ".ajpg");
            }
            return param1;
        }// end function

        public static function bitAND(... args) : uint
        {
            args = 4294967295;
            var _loc_3:uint = 0;
            while (_loc_3 < args.length)
            {
                
                args = args & args[_loc_3];
                _loc_3 = _loc_3 + 1;
            }
            return args;
        }// end function

        public static function bitOR(... args) : uint
        {
            args = 0;
            var _loc_3:uint = 0;
            while (_loc_3 < args.length)
            {
                
                args = args | args[_loc_3];
                _loc_3 = _loc_3 + 1;
            }
            return args;
        }// end function

    }
}
